import { login } from '@/api/login.js'

let actions = {
    updateAccount: function(value){
        return {
            type: 'updateAccount',
            value
        }
    },
    updatePassword: function(value){
        return {
            type: 'updatePassword',
            value
        }
    },
    updateLoginStatus: function(value){
        return {
            type: 'updateLoginStatus',
            value
        }
    },
    login: function(account, password){
        return function(dispatch){
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    let res = {
                        error: '',
                        status: true,
                        time: new Date().getTime()
                    }
                    dispatch(actions.updateLoginStatus(res))
                    resolve(res)
                }, 1500)
                // login({account, password}).then(res => {
                //     if(res.status){
                //         dispatch(actions.updateLoginStatus(res))
                //     }
                //     resolve(res)
                // }).catch(e => {
                //     reject(e)
                // })
            })
        }
    },
    logout: function(){
        return {
            type: 'logout'
        }
    },
    updateAuthRouter: function(value){
        return {
            type: 'setAuthRouter',
            value
        }
    }
}

export default actions